package com.ruoyi.business.dbopt.vo;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result<T> {
    private String message;
    private int code;
    private T data;

    public Result() {
    }

    public static <T> Result<T> just(String message, int code, T data){
        return new Result<>(message, code, data);
    }

    public static <T> Result<T> success(){
        return new Result<>(ResponseMsg.SUCCESS, 1, null);
    }

    public static <T> Result<T> success(T data){
        return new Result<>(ResponseMsg.SUCCESS, 1, data);
    }

    public static <T> Result<T> fail(){
        return new Result<>(ResponseMsg.FAIL, -1, null);
    }

    public static <T> Result<T> fail(String message){
        return new Result<>(message, -1, null);
    }

    public static <T> Result<T> notLogin(){
        return new Result<>(ResponseMsg.NOT_LOGIN, 0, null);
    }

    public static class ResponseMsg {

        public static final String SUCCESS = "操作成功";
        public static final String FAIL = "操作失败";
        public static final String NOT_LOGIN = "未登录";
        public static final String SYS_ERROR = "系统错误，请稍后重试";
    }
}
